package com.zhuiyun.educations.api.course.mapper;

import com.zhuiyun.educations.api.course.entity.Course;
import com.zhuiyun.educations.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
* @Author 杨友朋
* @Description
* @Date 2023/6/16 9:17
*/

@Mapper
public interface CourseMapper extends BaseMapper<Course> {

    /**
     * @Author yangze
     * @Description  明星教师课程查询
     * @Date 2023/6/26 11:25
     * @Return
     * @param teacherId
     */
    @Select("select  course_title, introduction AS course_content,image_id from course_info where teacher_id=#{teacherId}")
    List<Course> selectByTeacherId(Integer teacherId);

    @Update("<script>" +
            "update course set " +
            "<if test='courseTitle!=null'>course_title=#{courseTitle},</if> " +
            "<if test='courseContent!=null'>course_content=#{courseContent},</if> " +
            "<if test='parentSubjectId!=null'>parent_subject_id=#{parentSubjectId},</if> " +
            "<if test='subjectId!=null'>subject_id=#{subjectId},</if> " +
            "<if test='teacherId!=null'>teacher_id=#{teacherId},</if> " +
            "<if test='imageId!=null'>image_id=#{imageId},</if> " +
            "<if test='payType!=null'>pay_type=#{payType} </if> " +
            "where id=#{id}" +
            "</script>")
    Integer updateCourseById(Course course);

    /**
    * @Author 杨友朋
    * @Description TODO 添加
    * @Date 2023/6/26 20:27
    * @Return Integer
    * @param course
    */
    @Insert("insert into course (course_title,course_content,parent_subject_id,subject_id,teacher_id,pay_type,image_id,information_id,create_time,update_time) values (" +
            "#{courseTitle},#{courseContent},#{parentSubjectId},#{subjectId},#{teacherId},#{payType},#{imageId},#{informationId},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insertCourse(Course course);
    @Select("select * from course where id=#{id}")
    Course selectById(Integer id);
    /**
     * @Author 杨友朋
     * @Description TODO 根据id删除课程
     * @Date 2023/6/21 20:23
     * @Return Integer
     * @param id
     */
    @Update("update course set del_flag=1 where id=#{id}")
    Integer deleteCourseById(Integer id);

    /**
     * @Author 杨友朋
     * @Description TODO 根据id修改课程状态
     * @Date 2023/6/21 20:23
     * @Return Integer
     * @param course
     */
    @Update("update course set course_status=#{courseStatus} where id=#{id}")
    Integer updateStatusById(Course course);

    /**
     * @Author 杨友朋
     * @Description TODO 根据ids批量删除课程
     * @Date 2023/6/21 20:24
     * @Return Integer
     * @param ids
     */
    @Update("<script>" +
            "update course set del_flag=1 where id IN " +
            " <foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "            #{id}" +
            "        </foreach>" +
            "</script>")
    Integer deleteCourseByIds(@Param(value = "ids") List<Integer> ids);

    /**
     * @Author 杨友朋
     * @Description TODO 根据ids批量修改课程状态
     * @Date 2023/6/21 20:24
     * @Return Integer
     * @param ids,course
     */
    @Update("<script>" +
            "update course set course_status=#{courseStatus} where id IN " +
            " <foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "            #{id}" +
            "        </foreach>" +
            "</script>")
    Integer updateCourseByIds(@Param(value = "ids") List<Integer> ids,Course course);

}
